/*
 * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef KH_SLE_ANNOUNCE_H
#define KH_SLE_ANNOUNCE_H

#ifdef __cplusplus
extern "C" {
#endif // __cplusplus

#include "sle_error_code.h"
#include "sle_announce_config.h"
#include <stdbool.h>
#include <stdlib.h>
/**
 *   @brief   Announce state change Callbacks
 *
 *   @param   [in] announceId
 *   @param   [in] announceState
 *   @param   [in] isTerminaled - whether the host is connected while announcing
 *   @return  None
 */
typedef void (*SleAnnounceStateChangeCallback)(uint8_t announceId, SleAnnounceState announceState, bool isTerminaled);

typedef struct {
    SleAnnounceStateChangeCallback OnSleAnnounceStateChangeCb;
} SleAnnounceCallbacks;

/**
 *   @brief   Init SleAnnounceService sync
 *
 *   @param   None
 *   @return  SleErrorCode - operation result
 */
SleErrorCode InitSleAnnounceService(void);

/**
 *   @brief   Deinit SleAnnounceService sync
 *
 *   @param   None
 *   @return  SleErrorCode - operation result
 */
SleErrorCode DeinitSleAnnounceService(void);

/**
 *  @brief  add announce service sync
 *
 *  @param  [out] announceId - announceId will less than SLE_MAX_ANNOUNCE_ID_NUM
 *
 *  @return SleErrorCode - operation result
 */
SleErrorCode AddAnnounce(uint8_t *announceId);

/**
 *  @brief  remove announce service sync
 *
 *  @param  [in] announceId
 *  @return SleErrorCode - operation result
 */
SleErrorCode RemoveAnnounce(uint8_t announceId);

/**
 *   @brief   Start announce
 *
 *   @param   [in] announceId
 *   @param   [in] data
 *   @param   [in] announceParam
 *   @return  SleErrorCode - operation result
 *
 *   @note    dataLen mast less then SLE_ANNOUNCE_DATA_ANN_MAX_LENGTH or SLE_ANNOUNCE_DATA_MAX_RSP_LENGTH
 *   @attention if announceParam is not NULL, all params of announceParam should be set by user
 */
SleErrorCode StartAnnounce(uint8_t announceId, SleAnnounceData *data, const SleAnnounceParam *announceParam);

/**
 *   @brief   Stop announce
 *
 *   @param   [in] announceId
 *   @return  SleErrorCode - operation result
 *
 *   @note    this func will try to Unregister callback
 */
SleErrorCode StopAnnounce(uint8_t announceId);

/**
 *  @brief  get deault announce param sync
 *
 *  @param  [out] announceConfig - announce param config
 *  @return SleErrorCode - operation result
 */
SleErrorCode GetDefaultAnnounceParamConfig(SleAnnounceParam *announceConfig);

/**
 *   @brief   Register announce callback sync
 *
 *   @param   [in] announceCallback
 *   @return  SleErrorCode - operation result
 *
 *   @attention   announceCallback must be registered before StartAnnounce to get announceId
 */
SleErrorCode RegisterAnnounceCallbacks(SleAnnounceCallbacks *announceCallback);

/**
 *   @brief   Register announce callback sync
 *
 *   @param   [in] announceCallback
 *   @return  SleErrorCode - operation result
 *
 *   @note    announceCallback should be delete by user when not needed
 */
SleErrorCode UnregisterAnnounceCallbacks(SleAnnounceCallbacks *announceCallback);

#ifdef __cplusplus
}
#endif // __cplusplus

#endif // SLE_ANNOUNCE_C_H